<?php

use source\core\front\FrontApplication;
use source\aii;
use source\libs\Common;

defined('DS') or define('DS',DIRECTORY_SEPARATOR);
defined('FRONTEND_APP_PATH') or define('FRONTEND_APP_PATH',__DIR__);
defined('WEB_APP_ROOT') or define('WEB_APP_ROOT',__DIR__.DS.'..'.DS);

// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', true); // hewei  open default : 'dev'

if(!file_exists(WEB_APP_ROOT.'data'.DS.'install.lock')){
    return include(WEB_APP_ROOT.'install'.DS.'index.php');
}


require (WEB_APP_ROOT . 'vendor'.DS.'autoload.php');
require (WEB_APP_ROOT . 'vendor'.DS.'yiisoft'.DS.'yii2'.DS.'Yii.php');

require (WEB_APP_ROOT . 'source'.DS.'override.php');

require (WEB_APP_ROOT . 'data'.DS.'config'.DS.'bootstrap.php');
require (WEB_APP_ROOT . 'backend'.DS.'config'.DS.'bootstrap.php');


$config = yii\helpers\ArrayHelper::merge(
    require(WEB_APP_ROOT . 'data'.DS.'config'.DS.'main.php'),
    require(WEB_APP_ROOT . 'data'.DS.'config'.DS.'main-local.php'),
    require(WEB_APP_ROOT . 'frontend'.DS.'config'.DS.'main.php'),
    require(WEB_APP_ROOT . 'frontend'.DS.'config'.DS.'main-local.php')
);

Common::checkInstall($config);


$app = new FrontApplication($config);
$siteStatus = Common::getConfigValue('sys_status');

if($siteStatus === '0')
{
    $app->catchAll = ['site/close', 'message' => 'test'];
}

return $app ;
